import 'package:equatable/equatable.dart';

/// 点赞模型
/// 使用Equatable实现相等性比较
class LikeModel extends Equatable {
  /// 点赞ID
  final String id;

  /// 点赞用户ID
  final String userId;

  /// 被点赞的帖子ID
  final String postId;

  /// 点赞时间
  final DateTime likeTime;

  const LikeModel({
    required this.id,
    required this.userId,
    required this.postId,
    required this.likeTime,
  });

  /// 从JSON创建点赞对象
  factory LikeModel.fromJson(Map<String, dynamic> json) {
    return LikeModel(
      id: json['id'] as String,
      userId: json['userId'] as String,
      postId: json['postId'] as String,
      likeTime: DateTime.parse(json['likeTime'] as String),
    );
  }

  /// 转换为JSON
  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'userId': userId,
      'postId': postId,
      'likeTime': likeTime.toIso8601String(),
    };
  }

  /// 复制并修改部分属性
  LikeModel copyWith({
    String? id,
    String? userId,
    String? postId,
    DateTime? likeTime,
  }) {
    return LikeModel(
      id: id ?? this.id,
      userId: userId ?? this.userId,
      postId: postId ?? this.postId,
      likeTime: likeTime ?? this.likeTime,
    );
  }

  @override
  List<Object?> get props => [id, userId, postId, likeTime];

  @override
  String toString() {
    return 'LikeModel(id: $id, userId: $userId, postId: $postId, likeTime: $likeTime)';
  }
}
